package com.fast.cron.servlet;

import com.fast.cron.common.server.AjaxResponseBody;
import com.fast.cron.common.server.HttpRequestsUtils;
import com.fast.cron.common.server.JsonUtils;
import com.fast.cron.common.server.ResponseResultEnum;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author: Leo Jie
 * @date: 2018-10-07 21:15
 * @version: v1.0
 */
public abstract class AbstractFastCronServlet extends HttpServlet {
    void successResponseResult(HttpServletResponse response) {
        JsonUtils.json(response, AjaxResponseBody.of(ResponseResultEnum.SUCCESS.getCode(),
                ResponseResultEnum.SUCCESS.getMessage()));
    }

    void errorResponseResult(HttpServletResponse response, String errorMessage) {
        JsonUtils.json(response, AjaxResponseBody.of(ResponseResultEnum.FAILTURE.getCode(),
                errorMessage));
    }

    boolean hasParam(HttpServletRequest request, String param) {
        return HttpRequestsUtils.hasParam(request, param);
    }

    String getParam(HttpServletRequest request, String name) throws ServletException {
        return HttpRequestsUtils.getParam(request, name);
    }
}